import { BookItem } from '../types/book'
import { CommonResult, PageParams, PageResult } from '../types/global'
import { CategorySearchParams, HotItem, SearchHistoryItem, SearchParams } from '../types/search'
import { http } from '@/utils/http'




/**
 * 分类查询书籍
 * @param params 查询参数
 * @param pageParams 分页参数
 * @returns 书籍列表
 */
export const pageBooksByCategoryAPI = (
	params : CategorySearchParams,
	pageParams : PageParams
) => {
	return http<PageResult<BookItem[]>>({
		url: '/fanqie/books/pageBooksByCategory',
		method: 'GET',
		data: {
			current: pageParams.current,
			size: pageParams.size,
			searchName: params.name,
			tagList: params.tagList,
			searchBookWordCountType: params.wordCount,
			searchBookStatusType: params.status,
			searchBookType: params.type
		}
	})
}



/**
 * 初始化热门搜索列表
 * @returns
 */
export const queryHotSearchListAPI = () => {
	return http<HotItem[]>({
		url: '/fanqie/bookRanksRelation/queryHotSearchList',
		method: 'GET',
	})
}

/**
 * 初始化搜索历史列表
 *  
 */
export const querySearchHistoryAPI = () => {
	return http<SearchHistoryItem[]>({
		url: '/fanqie/searchHistory/querySearchHistory',
		method: 'GET',
	})
}

/**
 * 搜索建议
 * @param searchKeyword 搜索关键词
 * @returns 搜索建议列表
 */
export const queryRecommendSearchNameAPI = (searchKeyword : string) => {
	return http<BookItem[]>({
		url: '/fanqie/books/queryRecommendSearchName',
		method: 'GET',
		data: {
			name: searchKeyword,
		}
	})
}

/**
 * 分类查询书籍
 * @param params 查询参数
 * @param pageParams 分页参数
 * @returns 书籍列表
 */
export const pageQueryBookByCategoryAPI = (
	params : CategorySearchParams,
	pageParams : PageParams
) => {
	return http<PageResult<BookItem[]>>({
		url: '/fanqie/books/pageQueryBookByCategory',
		method: 'GET',
		data: {
			current: pageParams.current,
			size: pageParams.size,
			searchName: params.name,
			tagList: params.tagList,
			searchBookWordCountType: params.wordCount,
			searchBookStatusType: params.status,
			searchBookType: params.type
		}
	})
}


/**分页查询
 * 根据搜索名称查询书籍
 * @param searchKeyword 搜索名称
 * @returns 书籍列表
 */
export const pageQueryBookBySearchKeywordAPI = (
	params : SearchParams,
	pageParams : PageParams
) => {
	return http<PageResult<BookItem[]>>({
		url: '/fanqie/books/pageQueryBookBySearchKeyword',
		method: 'GET',
		data: {
			current: pageParams.current,
			size: pageParams.size,
			name: params.bookName
		}
	})
}


/**
 * 根据搜索关键字查询书籍
 * @param searchKeyword 搜索关键字
 * @returns 书籍列表
 */
export const querySearchBookApi = (searchKeyword : string) => {
	return http<BookItem[]>({
		url: '/fanqie/books/querySearchBook',
		method: 'GET',
		data: {
			name: searchKeyword,
		}
	})
}